package com.zjxny.model;

import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Drill;
import xyz.erupt.annotation.sub_erupt.Link;
import xyz.erupt.annotation.sub_erupt.LinkTree;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_erupt.RowOperation;
import xyz.erupt.annotation.sub_erupt.Tpl;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.BoolType;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.DateType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTableType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.upms.handler.DictCodeChoiceFetchHandler;
import xyz.erupt.upms.model.base.HyperModel;

@Setter
@Getter
@Entity
@Table(name = "car_info") //field 的值为类中支持树组件字段)
@Erupt(name = "车辆信息",linkTree = @LinkTree(field = "accountInfo")
//	,dataProxy = CarInfoProxy.class
	,power = @Power(
			add = true
			,viewDetails=false
			,delete = false
			,edit = true, query = true
			,importable = false, export = true
	)
	,rowOperation= {
			@RowOperation(
					title="实时查询违章",
					type = RowOperation.Type.TPL,
					icon = "fa fa-search",
	                tpl = @Tpl(
	                        path = "/tpl/freemarker/traffic_result.ftl",
	                        tplHandler=CarInfo.class,
	                        engine = Tpl.Engine.FreeMarker
	                )
			),
			@RowOperation(
					title="机动车二维码",
					type = RowOperation.Type.TPL,
					icon = "fa fa-qrcode",
					ifExpr="'是'==item.isNotOperation",
	                tpl = @Tpl(
	                        path = "/tpl/freemarker/carqr.ftl",     //模板文件路径
	                        tplHandler=CarInfo.class,
	                        engine = Tpl.Engine.FreeMarker
	                )
			),
			@RowOperation(
					title="合格标志电子凭证",
					type = RowOperation.Type.TPL,
					icon = "fa fa-id-card",
					ifExpr="'是'==item.isNotOperation",
	                tpl = @Tpl(
	                        path = "/tpl/freemarker/card.ftl",     //模板文件路径
	                        tplHandler=CarInfo.class,
	                        engine = Tpl.Engine.FreeMarker
	                )
			)
			//合格标志电子凭证
			/*,
			@RowOperation( 
                    title = "未违章车辆清单", 
                    type = RowOperation.Type.TPL,
//                    operationHandler = OperationHandlerImpl.class,
                    mode = RowOperation.Mode.BUTTON, 
                    tip = "不依赖任何数据即可执行")*/
	}
	,drills = {
            @Drill(code = "drill", 
                    title = "违章明细",
                    //最终生成的表达式为：EruptTest.id = DrillErupt.eruptTestId
                    link = @Link(column = "hphm",                // 当前表关联列
                                 linkErupt = TrafficDetail.class, // 目标关联表
                                 joinColumn = "hphm"))  // 目标表关联列
    }
)
//@Erupt(name = "车辆信息")
public class CarInfo extends HyperModel implements Tpl.TplHandler{

	private static final long serialVersionUID = 5127675028647241654L;
	
	@EruptField(
	        views =  @View(title = "所属公司", column = "simpleTitle"),
    		edit = @Edit(
    		            title = "所属公司"
    		            ,type = EditType.REFERENCE_TREE
    		            ,referenceTreeType = @ReferenceTreeType(pid = "parent.id",label = "simpleTitle")
    		)
	    )
	@ManyToOne
	AccountInfo accountInfo;
	
	@EruptField(
			views = {
			        @View(title = "姓名", column = "userName"),
			        @View(title = "手机号", column = "phoneNo")
			    },
    		edit = @Edit(
    		            title = "客户"
	            		,type = EditType.REFERENCE_TABLE
	                	,referenceTableType = @ReferenceTableType(id = "id", label = "userName")
    		            ,search = @Search(vague = true)
    		)
	    )
	@ManyToOne
	CustomerInfo customerInfo;
	
	@EruptField(views = @View(title = "号牌种类",show = false), edit = @Edit(show=false,title = "号牌种类"))
	String hpzl;// "52",
	
	@Column(name = "hpzl_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "号牌种类",show=false), edit = @Edit(show=false,title = "号牌种类"))
	String hpzlStr;// "小型新能源汽车",
	
	@EruptField(views = @View(title = "号牌号码"), edit = @Edit(title = "号牌号码",search=@Search(vague=true)))
	String hphm;// "粤BDA2028",
	
	@EruptField(views = @View(title = "发动机号",show=false), edit = @Edit(show=false,title = "发动机号"))
	String fdjh;// "",
	
	@EruptField(views = @View(title = "车辆类型",show = false), edit = @Edit(show=false,title = "车辆类型"))
	String cllx;// "H33",
	
	@Column(name = "cll_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "车辆类型",show=false), edit = @Edit(show=false,title = "车辆类型"))
	String cllxStr;// "轻型封闭式货车",
	
	@Column(name = "zt_str", columnDefinition="varchar(20)")
	@EruptField(views = @View(title = "状态",show=false), edit = @Edit(show=false,title = "状态"))
	String ztStr;// "违法未处理",

	@EruptField(views = @View(title = "状态"), edit = @Edit(show=false,title = "状态"
			,search=@Search
			,type = EditType.CHOICE
			,choiceType=@ChoiceType(fetchHandler = DictCodeChoiceFetchHandler.class,fetchHandlerParams = {"traffic_zt"} ) ) )
	String zt;
	
	@EruptField(views = @View(title = "有效期止"), edit = @Edit(show=false,title = "有效期止",search=@Search(vague=true),type = EditType.DATE, dateType = @DateType(type = DateType.Type.DATE)))
	@Column(name = "yxqz", columnDefinition="date")
	Date yxqz;// "2024-03-31",
	
	@EruptField(views = @View(title = "逾期检验强制报废期止"), edit = @Edit(show=false,title = "逾期检验强制报废期止",type = EditType.DATE,search = @Search(vague=true), dateType = @DateType(type = DateType.Type.DATE)))
	@Column(name = "yqjyqzbfqz", columnDefinition="date")
	Date yqjyqzbfqz;// "2027-03-31",
	
	@EruptField(views = @View(title = "强制报废期止"), edit = @Edit(show=false,title = "强制报废期止"
			,search=@Search(vague=true)
			,type = EditType.DATE, dateType = @DateType(type = DateType.Type.DATE)))
	@Column(name = "qzbfqz", columnDefinition="date")
	Date qzbfqz;// "2037-03-31",
	
	@EruptField(views = @View(title = "发证机关",show=false), edit = @Edit(show=false,title = "发证机关"))
	String fzjg;// "粤B",

	@EruptField(views = @View(title = "xh",show = false), edit = @Edit(show=false,title = "xh"))
	@Column(name = "xh", columnDefinition="char(14)")
	String xh;// "44030022803430",
	
	@EruptField(views = @View(title = "车架号"), edit = @Edit(show=false,title = "车架号"))
	String clsbdh;// "",
	
	@EruptField(views = @View(title = "sfzmhm",show = false), edit = @Edit(show=false,title = "sfzmhm"))
	String sfzmhm;// "914403********EY3P",
	
	@EruptField(views = @View(title = "sfzmmc",show = false), edit = @Edit(show=false,title = "sfzmmc"))
	String sfzmmc;// "N",
	
	@Column(name = "zfzmmc_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "sfzmmc",show = false), edit = @Edit(show=false,title = "sfzmmc"))
	String sfzmmcStr;// "统一社会信用代码",

	@EruptField(views = @View(title = "手机号码",show = false), edit = @Edit(show=false,title = "手机号码"))
	String sjhm;// "155****1317",
	
	@EruptField(views = @View(title = "dzyx",show = false), edit = @Edit(show=false,title = "dzyx"))
	String dzyx;// "",
	
	@EruptField(views = @View(title = "gxsj",show = false), edit = @Edit(show=false,title = "gxsj"))
	String gxsj;// null,
	
	@EruptField(views = @View(title = "车辆品牌",show = false), edit = @Edit(show=false,title = "车辆品牌"))
	String clpp1;// "",
	
	@EruptField(views = @View(title = "电子监控条数"), edit = @Edit(show=false,title = "dzjk"))
	String dzjk;// "2",
	
	@EruptField(views = @View(title = "所有人",show = false), edit = @Edit(show=false,title = "所有人"))
	String syr;// "绿的城配***********有限公司",

	@EruptField(views = @View(title = "使用性质",show = false), edit = @Edit(show=false,title = "使用性质"))
	String syxz;// "A",
	
	@EruptField(views = @View(title = "使用性质"), edit = @Edit(show=false,title = "使用性质"))
	String syxzStr;//
	
	@EruptField(views = @View(title = "zzz",show = false), edit = @Edit(show=false,title = "zzz"))
	String zzz;// null,
	
	@EruptField(views = @View(title = "glbm",show = false), edit = @Edit(show=false,title = "glbm"))
	String glbm;// "440304000400",
	
	@EruptField(views = @View(title = "own",show = false), edit = @Edit(show=false,title = "own"))
	String own;// false,
	
	@EruptField(views = @View(title = "yzbm",show = false), edit = @Edit(show=false,title = "yzbm"))
	String yzbm1;// "518000",
	
	@EruptField(views = @View(title = "sfgk",show = false), edit = @Edit(show=false,title = "sfgk"))
	String sfgk;// null,
	
	@EruptField(views = @View(title = "车辆型号",show = false), edit = @Edit(show=false,title = "车辆型号"))
	String clxh;// "DFA5030XXYMBEV1",
	
	@EruptField(views = @View(title = "sfxny",show = false), edit = @Edit(show=false,title = "sfxny"))
	String sfxny;// "1",
	
	@EruptField(views = @View(title = "新能源种类",show = false), edit = @Edit(show=false,title = "新能源种类"))
	String xnyzl;// "A",
	
	@Column(name = "xnyzl_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "新能源种类",show = false), edit = @Edit(show=false,title = "新能源种类"))
	String xnyzlStr;// "纯电动",
	
	@EruptField(views = @View(title = "fjsx",show = false), edit = @Edit(show=false,title = "fjsx"))
	String fjsx;// null,
	
	@EruptField(views = @View(title = "hpqysj",show = false), edit = @Edit(show=false,title = "hpqysj"))
	String hpqysj;// "20220331",
	
	@EruptField(views = @View(title = "号牌状态",show = false), edit = @Edit(show=false,title = "号牌状态"))
	String hpzt;// null,
	
	@Column(name = "hpzt_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "号牌状态",show = false), edit = @Edit(show=false,title = "号牌状态"))
	String hpztStr;// null,
	
	@EruptField(views = @View(title = "sfkhp",show = false), edit = @Edit(show=false,title = "sfkhp"))
	String sfkhp;// "1",
	
	@EruptField(views = @View(title = "sfsd",show = false), edit = @Edit(show=false,title = "sfsd"))
	String sfsd;// "1",
	
	@EruptField(views = @View(title = "dybj",show = false), edit = @Edit(show=false,title = "dybj"))
	String dybj;// "1",
	
	@Column(name = "dybj_str", columnDefinition="varchar(40)")
	@EruptField(views = @View(title = "dybj",show = false), edit = @Edit(show=false,title = "dybj"))
	String dybjStr;// null,
	
	@EruptField(views = @View(title = "bdsj",show = false), edit = @Edit(show=false,title = "bdsj"))
	String bdsj;// null,
	
	@EruptField(views = @View(title = "bdveh",show = false), edit = @Edit(show=false,title = "bdveh"))
	String bdveh;// false,
	
	@EruptField(views = @View(title = "zlkssj",show = false), edit = @Edit(show=false,title = "zlkssj"))
	String zlkssj;// null,
	
	@EruptField(views = @View(title = "zljssj",show = false), edit = @Edit(show=false,title = "zljssj"))
	String zljssj;// null,
	
	@EruptField(views = @View(title = "zlxh",show = false), edit = @Edit(show=false,title = "zlxh"))
	String zlxh;// null,
	
	@EruptField(views = @View(title = "zllx",show = false), edit = @Edit(show=false,title = "zllx"))
	String zllx;// null,
	
	@EruptField(views = @View(title = "rylx",show = false), edit = @Edit(show=false,title = "rylx"))
	String rylx;// null,
	
	@EruptField(views = @View(title = "basj",show = false), edit = @Edit(show=false,title = "basj"))
	String basj;// null,
	
	@EruptField(views = @View(title = "htbh",show = false), edit = @Edit(show=false,title = "htbh"))
	String htbh;// null,
	
	@EruptField(views = @View(title = "czsfzmhm",show = false), edit = @Edit(show=false,title = "czsfzmhm"))
	String czsfzmhm;// null,
	
	@EruptField(views = @View(title = "czsfzmmc",show = false), edit = @Edit(show=false,title = "czsfzmmc"))
	String czsfzmmc;// null,
	
	@EruptField(views = @View(title = "czxm",show = false), edit = @Edit(show=false,title = "czxm"))
	String czxm;// null,
	
	@EruptField(views = @View(title = "qufbrbasx",show = false), edit = @Edit(show=false,title = "qufbrbasx"))
	String qufbrbasx;// null,
	
	@EruptField(views = @View(title = "ccdjrq",show = false), edit = @Edit(show=false,title = "ccdjrq"))
	@Column(name = "ccdjrq", columnDefinition="date")
	Date ccdjrq;// "2022-03-31",
	
	@EruptField(views = @View(title = "bxgs",show = false), edit = @Edit(show=false,title = "bxgs"))
	String bxgs;// null,
	
	@EruptField(views = @View(title = "clyt",show = false), edit = @Edit(show=false,title = "clyt"))
	String clyt;// "P1",
	
	@EruptField(views = @View(title = "ytsx",show = false), edit = @Edit(show=false,title = "ytsx"))
	String ytsx;// "9"
	
	@EruptField(views = @View(title = "合格证标志号"), edit = @Edit(show=false,title = "合格证标志号"))
	String jyhgbzbh;
	
	@EruptField(views = @View(title = "检验机构"), edit = @Edit(show=false,title = "检验机构"))
	String cjdw;
	
//	@Transient   
	@EruptField(views = @View(title = "车架号-掩码",show=false), edit = @Edit(show=false,title = "车架号-掩码"))
	String clsbdhMask;

	@EruptField(
			views = @View(title = "非营运")
			, edit = @Edit(
				title = "非营运",
				type = EditType.BOOLEAN
				,search = @Search,
				boolType = @BoolType
			)
	)
	private Boolean isNotOperation=false;
	
	@EruptField(
			views = @View(title = "营运"),
			edit = @Edit(
				title = "营运",
				type = EditType.BOOLEAN
						,search = @Search,
						boolType = @BoolType
			)
	)
	private Boolean isOperation=false;
	
	@EruptField(
			views = @View(title = "租赁"),
			edit = @Edit(
				title = "租赁",
				type = EditType.BOOLEAN
						,search = @Search,
						boolType = @BoolType
			)
	)
	private Boolean isBiz=false;

	@EruptField(
			views = @View(title = "绑定")
			, edit = @Edit(
				title = "绑定",
				type = EditType.BOOLEAN
				,search = @Search,
				boolType = @BoolType
		)
	)
	private Boolean isBind=true;

	//任务执行状态
	@EruptField(
			views = @View(title = "任务状态",show = true)
			, edit = @Edit(
					title = "任务状态"
					,show = true
					,type = EditType.BOOLEAN
					,search = @Search,
					boolType = @BoolType
			)
	)
	private Boolean taskStatus=false;

	@Override
	public void bindTplData(Map<String, Object> binding, String[] params) {
		 binding.put("title", "选中的数据");
	}
}